package p1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Random;

public class ProxyTest {
	public static void main(String[] args){
		Object[] eles = new Object[1000];
		for(int i = 0 ; i< eles.length; i++){
			
			Integer value = i +1;
			Class[] interfaces = value.getClass().getInterfaces();
			// finger a class to some handler ..
			InvocationHandler handler = new TraceHandler(value);
			
			//handler and interfaces make a proxy ;
			Object proxy = Proxy.newProxyInstance(null, interfaces, handler);
			
		//	Object proxy = Proxy.newProxyInstance(null, new Class[]{xxx.class}, handler);
			eles[i] = proxy;
		}
		
		Integer key = new Random().nextInt(eles.length) + 1;
		
		int result = Arrays.binarySearch(eles, key);
		
		if(result >=0)
			System.out.println(eles[result]);
		
		
	}
}
